package com.cssw.fyzb.busi.api.appeal;

import com.cssw.fyzb.busi.api.task.CollecTask;
import com.cssw.fyzb.core.model.vo.appeal.AppealVo;
import com.cssw.fyzb.busi.service.appeal.AppealService;
import com.cssw.fyzb.core.model.dodb.Appeal;
import com.cssw.fyzb.core.util.DateUtil;
import com.ydn.appserver.Action;
import com.ydn.appserver.Request;
import com.ydn.appserver.Response;
import com.ydn.appserver.annotations.Function;
import com.ydn.appserver.annotations.Parameter;
import com.ydn.appserver.annotations.Type;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author
 */
@Function(description = "查看详情", parameters = {
        @Parameter(name = "appealId", type = Type.String, description = "申述标识", required = true)
})
@Component
public class GetAppeal implements Action {

    private final static Logger logger = LoggerFactory.getLogger(CollecTask.class);

    @Autowired
    private AppealService appealService;

    @Override
    public Response execute(Request request) throws Exception {
        try {
            Long appealId = request.getLong("appealId");
            Appeal appeal = appealService.getAppeal(appealId);
            AppealVo vo = new AppealVo();
            vo.setAppeal(appeal.getAppeal());
            vo.setAppealAttach(appeal.getAppealAttach());
            vo.setAppealId(appeal.getAppealId());
            vo.setAppealTime(DateUtil.format(appeal.getAppealTime()));
            vo.setAppealType(appeal.getAppealType());
            vo.setContact(appeal.getContact());
            vo.setStatus(appeal.getStatus());
            vo.setFeedback(appeal.getFeedback());
            vo.setFeedbackOperId(appeal.getFeedbackOperId());
            vo.setTypeName(appeal.getTypeName());
            vo.setFeedbackTime(appeal.getFeedbackTime());
            vo.setUserId(appeal.getUserId());
            vo.setTypeName(appeal.getStr("appeal_type_name"));
            return Response.success().put("data", vo);
        } catch (Exception e) {
            logger.debug("", e);
            return Response.fail("操作失败");
        }

    }
}
